<template>
  <div class="baseinfo" v-title data-title="对外科技合作立项界面">
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item label="项目编号" prop="projectNo" :label-col="{ span: 8 }" :wrapper-col="{ span: 15 }">
            {{form.projectNo}}
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="projectName"
            label="项目名称"
            prop="projectName"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input
              v-model="form.projectName"
              @blur="
                () => {
                  $refs.projectName.onFieldBlur()
                }
              "
              placeholder="总结概括需要进行对外科技合作的事项，拟定一个名称" 
              :disabled="form.status>1" 
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="项目分类"
            prop="projectTypeSubCategory"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <span style="color: #f7a961; margin: 0 6px; font-size: 16px">{{ subName }}</span>
          </a-form-model-item>
        </a-col>
      </a-row>
      
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            label="项目成果类型"
            prop="mgType"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <!-- <a-checkbox-group v-model="form.mgType" :options="techMgTypeOption"> </a-checkbox-group> -->
            <a-select
              v-model="form.mgType"
              placeholder="请选择项目成果类型"
              :options="techMgTypeOption"
              @change="mgTypeChange"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="hatchProjectNo"
            label="孵化项目编号"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input v-model="form.hatchProjectNo" placeholder="点击选择孵化项目" @click="hatch.visible = true"  :disabled="form.status>1" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="hatchProjectName"
            label="孵化项目名称"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input v-model="form.hatchProjectName" disabled />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            ref="demandDeptId"
            label="需求提出部门"
            prop="demandDeptId"
          >
            <a-select
              v-model="demandDeptId"
              mode="multiple"
              placeholder="输入组织架构名称查找，多选，至少一个"
              style="width: 100%"
              :filter-option="false"
              :not-found-content="fetching ? '找不到记录' : '找不到记录'"
              @search="fetchDemandDept"
              @change="demandDeptChange"
            >
              <a-spin v-if="fetching" slot="notFoundContent" size="small" />
              <a-select-option v-for="(d, index) in demandDeptData" :key="index" :value="d.deptId">
                {{ d.deptName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="landingDeptId"
            label="项目实施部门"
            prop="landingDeptId"
          >
            <a-select
              v-model="landingDeptId"
              mode="multiple"
              placeholder="输入组织架构名称查找，多选，至少一个"
              style="width: 100%"
              :filter-option="false"
              :not-found-content="fetching ? '找不到记录' : '找不到记录'"
              @search="fetchLandingDept"
              @change="landingDeptChange"
            >
              <a-spin v-if="fetching" slot="notFoundContent" size="small" />
              <a-select-option v-for="(d, index) in landingDeptData" :key="index" :value="d.deptId">
                {{ d.deptName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="implementPlace"
            label="实施地点"
            prop="implementPlace"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input
              v-model="form.implementPlace"
              @blur="
                () => {
                  $refs.implementPlace.onFieldBlur()
                }
              "
              placeholder="项目预计实施地点" 
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            ref="teamAid"
            label="需求方负责人"
            prop="teamAid"
          >
            <a-select
              v-model="teamAid"
              mode="multiple"
              placeholder="输入账号或者名称查找用户，多选，至少一个"
              style="width: 100%"
              :filter-option="false"
              :not-found-content="fetching ? '找不到记录' : '找不到记录'"
              @search="fetchAUser"
              @change="fetchAChange"
            >
              <a-spin v-if="fetching" slot="notFoundContent" size="small" />
              <a-select-option v-for="(d, index) in userAData" :key="index" :value="d.username">
                {{ d.realname }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="projectLeaderName"
            label="实施方负责人"
            prop="projectLeaderName"
          >
            <a-select
              show-search
              :value="form.projectLeaderName"
              placeholder="输入账号或者名称查找用户,单选"
              style="width: 100%"
              :filter-option="false"
              :not-found-content="fetching ? '找不到记录' : '找不到记录'"
              @search="fetchLeaderUser"
              @change="fetchLeaderChange"
            >
              <a-spin v-if="fetching" slot="notFoundContent" size="small" />
              <a-select-option v-for="(d, index) in userLeaderData" :key="index" :value="d.username">
                {{ d.realname }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item
            ref="solvedProblem"
            label="项目引进说明"
            prop="solvedProblem"
            :label-col="{ span: 3 }"
            :wrapper-col="{ span: 21 }"
          >
            <a-textarea
              v-model="form.solvedProblem"
              @blur="
                () => {
                  $refs.solvedProblem.onFieldBlur()
                }
              "
              :auto-size="{ minRows: 3, maxRows: 5 }"
              style="width: 100%"
              placeholder="拟引进项目解决什么问题，该问题的急迫性和重要性，500字内"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item
            ref="economyTarget"
            label="项目价值效益"
            prop="economyTarget"
            :label-col="{ span: 3 }"
            :wrapper-col="{ span: 21 }"
          >
            <a-textarea
              v-model="form.economyTarget"
              @blur="
                () => {
                  $refs.economyTarget.onFieldBlur()
                }
              "
              :auto-size="{ minRows: 3, maxRows: 5 }"
              style="width: 100%"
              placeholder="请填写项目预期价值，300字内"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item
            ref="functionAndPerformance"
            label="项目验收指标"
            prop="functionAndPerformance"
            :label-col="{ span: 3 }"
            :wrapper-col="{ span: 21 }"
          >
            <a-textarea
              v-model="form.functionAndPerformance"
              @blur="
                () => {
                  $refs.functionAndPerformance.onFieldBlur()
                }
              "
              :auto-size="{ minRows: 3, maxRows: 5 }"
              style="width: 100%"
              placeholder="请预设项目验收指标，500字内"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <br/>
      <h3 style="font-weight:bold;">合作信息:</h3>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            ref="cooperationType"
            label="项目合作方式"
            prop="cooperationType"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <!-- <a-checkbox-group v-model="form.cooperationType" :options="cooperationTypeOptions"> </a-checkbox-group> -->
            <a-select
              v-model="form.cooperationType"
              placeholder="请选择项目合作方式"
              :options="cooperationTypeOptions"
              @change="cooperationTypeChange"
            >
              <a-icon slot="suffixIcon" type="plus" />
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="budgetCost"
            label="预期合作金额"
            prop="budgetCost"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input
              v-model="form.budgetCost"
              @blur="
                () => {
                  $refs.budgetCost.onFieldBlur()
                }
              "
              placeholder="请输入预期合作金额（万元）"
              type="number"
            >
            <span slot="addonAfter">万元</span>
            </a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
            <a-form-model-item
              ref="hopeStartDate"
              label="项目实施周期"
              prop="hopeStartDate"
              :label-col="{ span: 8 }"
              :wrapper-col="{ span: 15 }"
            >
              <a-range-picker v-model="hopeDateRange"  @change="onDateRangeChange" style="width:100%"/>
            </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="8">
          <a-form-model-item
            ref="partnerCompany"
            label="合作方名称"
            prop="partnerCompany"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input
              v-model="form.partnerCompany"
              @blur="
                () => {
                  $refs.partnerCompany.onFieldBlur()
                }
              "
              placeholder="请填写合作方全称" 
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="partnerName"
            label="合作方负责人"
            prop="partnerName"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input
              v-model="form.partnerName"
              @blur="
                () => {
                  $refs.partnerName.onFieldBlur()
                }
              "
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            ref="partnerPhone"
            label="合作方联系方式"
            prop="partnerPhone"
            :label-col="{ span: 8 }"
            :wrapper-col="{ span: 15 }"
          >
            <a-input
              v-model="form.partnerPhone"
              @blur="
                () => {
                  $refs.partnerPhone.onFieldBlur()
                }
              "
              placeholder="填写手机号"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-form-model-item
            ref="otherReq"
            label="项目其他说明"
            prop="otherReq"
            :label-col="{ span: 3 }"
            :wrapper-col="{ span: 21 }"
          >
            <a-textarea
              v-model="form.otherReq"
              @blur="
                () => {
                  $refs.otherReq.onFieldBlur()
                }
              "
              :auto-size="{ minRows: 3, maxRows: 5 }"
              style="width: 100%"
              placeholder="其他说明，请补充填写，500字内"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <five-to-five ref="fiveForm" :projectBuildId="projectBuildId" :change-id="changeId" @addField="addFiveDataToForm"/>
    </a-form-model>

    <pagination-select
      :title="hatch.title"
      :searchPlaceholder="hatch.searchPlaceholder"
      :visible="hatch.visible"
      :url="hatch.url"
      :columns="hatch.columns"
      @hatchHandleOk="hatchHandleOk"
    />
  </div>
</template>
<script>
import $ from 'jquery'
import { getAction, getActionAsync, postAction, postActionAsync } from '@/api/manage'
import { getParamValFromUrl, strNotNull } from '@/utils/common.js'
import { Modal } from 'ant-design-vue'
import Vue from 'vue'
export default {
  components: {
    PaginationSelect: () => import('@/components/tools/PaginationSelect'),
    FiveToFive: () => import('@/components/tools/projectBuildStup/baseInfo/FiveToFive')
  },
  props: {
    projectBuildId: {
      Type: String,
      default: '',
    },
    changeId: {
      Type: String,
      default: '',
    },
    selProjectType: {
      Type: String,
      default: '',
    }
  },
  data() {
    return {
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      form: {
        id:'',
        projectClass: '62',
        projectNo: '',
        projectName: '',
        projectTypeSubCategory: '',
        hatchProjectId: '',
        hatchProjectNo: '',
        hatchProjectName: '',
        teamAname: '',
        teamAid: '',
        landingDeptName: '',
        landingDeptId: '',
        demandDeptName: '',
        demandDeptId: '',
        projectLeaderName: undefined,
        projectLeaderId: '',
        implementPlace: '',
        solvedProblem: '', 
        economyTarget: '', 
        functionAndPerformance: '', 
        budgetCost: '', 
        hopeStartDate: '', 
        hopeEndDate: '', 
        partnerCompany: '', 
        partnerName: '', 
        partnerPhone: '', 
        otherReq: '', 
        mgType:undefined,
        mgTypeName:'',
        cooperationType:undefined,
        cooperationTypeName:'',
        status: 0
      },
      rules: {
        projectName: [
          { required: true, message: '总结概括需要进行对外科技合作的事项，拟定一个名称', trigger: 'blur' },
          { min: 1, max: 50, message: '项目名不超过50个字符', trigger: 'blur' },
        ],
        mgType: [{ required: true, message: '请选择项目成果类型', trigger: 'change' }],
        implementPlace: [
          { required: true, message: '请输入实施地点', trigger: 'blur' },
          { min: 1, max: 150, message: '实施地点不超过150个字符', trigger: 'blur' },
        ],
        solvedProblem: [
          { required: true, message: '请输入项目引进说明', trigger: 'blur' },
          { min: 1, max: 500, message: '项目引进说明不超过500个字符', trigger: 'blur' },
        ],
        economyTarget: [
          { required: true, message: '请输入项目价值效益', trigger: 'blur' },
          { min: 1, max: 300, message: '项目价值效益不超过300个字符', trigger: 'blur' },
        ],
        functionAndPerformance: [
          { required: true, message: '请输入项目验收指标', trigger: 'blur' },
          { min: 1, max: 500, message: '项目验收指标不超过500个字符', trigger: 'blur' },
        ],
        budgetCost: [
          { required: true, message: '请输入预期合作金额（万元）', trigger: 'blur' }
        ],
        hopeStartDate: [{ required: true, message: '请选择项目实施周期', trigger: 'change' }],
        cooperationType: [{ required: true, message: '请选择项目合作方式', trigger: 'change' }],
        partnerCompany: [{ required: true, message: '请输入合作方名称', trigger: 'blur' }],
        partnerName: [{ required: true, message: '请输入合作方负责人', trigger: 'blur' }],
        partnerPhone: [{ required: true, message: '请输入合作方的电话号码,', trigger: 'blur' }],
        demandDeptId: [{ required: true, message: '请选择需求提出部门', trigger: 'blur' }],
        teamAid: [{ required: true, message: '请选择经营班子A', trigger: 'blur' }],
        landingDeptId: [{ required: true, message: '请选择项目落地经营体', trigger: 'blur' }],
        projectLeaderName: [{ required: true, message: '请选择项目负责人', trigger: 'blur' }],
      },
      projectCategoryOptions: [],
      url: {
        codeInfoList: '/manage/codeInfo/list',
        getProjectByNo: '/projectBuild/getProjectByNo',
        save: '/projectBuild/add',
        queryVOById: '/projectBuild/queryVOById',
        getUserList: '/lib/hteFileClass/getUserListOnlyUpms',
        getDeptList: '/lib/hteFileClass/getDeptList',
      },
      loadFinish: false,
      subName: '',
      kpi: {
        columns: [
          {
            title: '序号',
            dataIndex: 'index',
            key: 'index',
            align: 'center',
            width: 100,
            customRender: (text,record,index) => `${index+1}`,
          },
          {
            title: '公司名称',
            dataIndex: 'companyName',
            scopedSlots: { customRender: 'companyName' },
          },
        ],
        data: [],
        selRowIds: [],
        freshKey: 0,
      },
      userAData:[],
      userLeaderData:[],
      techMgTypeOption:[],
      cooperationTypeOptions:[],
      fetching:false,
      btnShow: false,
      canDoSave: this.$route.query.canDoSave ? (this.$route.query.canDoSave=='true' ? true : false) : true,
      supplier: {
        visible: false,
        title: '请选择公司名称',
        searchPlaceholder: '输入公司编号或名称查询',
        url: '/rad/orgCompany/queryCompanyByHte',
        columns: [
          {
            title: '公司编号',
            dataIndex: 'code',
            align: 'center',
          },
          {
            title: '公司名称',
            dataIndex: 'name',
            align: 'center',
          },
          {
            title: '公司法人',
            dataIndex: 'corp',
            align: 'center',
          }
        ],
      },
      tableSelectKey:'',
      hopeDateRange:[],
      teamAid: undefined,
      landingDeptId: undefined,
      demandDeptId: undefined,
      demandDeptData:[],
      landingDeptData:[],
      hatch: {
        visible: false,
        title: '请选择孵化项目',
        searchPlaceholder: '输入代码或名称查询',
        url: '/hatchProject/listBySelect',
        columns: [
          {
            title: '孵化项目编号',
            dataIndex: 'hatchProjectNo',
            align: 'center',
          },
          {
            title: '孵化项目名称',
            dataIndex: 'hatchProjectName',
            align: 'center',
          },
        ],
      },
    }
  },
  computed: {
    rowSelection () {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.kpi.selRowIds = selectedRowKeys
        },
      }
    },
  },
  methods: {
    addFiveDataToForm(val,valRef) {
      this.$set(this.form, valRef, val)
    },
    async doSubmit() {
      if(!this.loadFinish){
        layer.message.warning('请等待页面加载完毕')
        return {}  
      }
      var validR=false;
      try{
        validR = await this.$refs.ruleForm.validate();
        validR = await this.$refs.fiveForm.checkFiveWriteStatus()
      }catch(e){
        validR = false;
      }
      console.log('validR',validR);
      this.form.validResult = validR;
      let res=await this.doSave();
        this.projectBuildId=res;
      return {valid:validR,id:res};
    },
    async doSave() {
      let flag=null;

      this.form.changeId=this.changeId;
      var formData = JSON.parse(JSON.stringify(this.form));

      var vm = this
      await postActionAsync(this.url.save, formData)
        .then((res) => {
          if (res.code == 200) {
            vm.form.id = res.result.id;
            vm.form.projectNo = res.result.projectNo;
            this.$message.success('保存成功')
            return flag=res.result.id;
          } else {
            this.$message.warning('保存数据出错:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('保存数据出错:' + res.message)
        })
        return flag;
    },
    resetForm() {
      this.$refs.ruleForm.resetFields()
    },
    //初始化项目子类
    initProjectCategoryOptions() {
      var vm = this
      getAction(this.url.codeInfoList, { type: '项目子类', isdel: 0, parentid: vm.form.projectClass,pageSize:-1 })
        .then((res) => {
          if (res.code == 200) {
            var list = res.result
            if (list != null) {
              list.records.map((item) => {
                vm.projectCategoryOptions.push({ value: item.code, label: item.name })
              })

              if (vm.projectCategoryOptions.length === 1) {
                vm.form.projectTypeSubCategory = vm.projectCategoryOptions[0].value
              }
            }
          } else {
            this.$message.warning('查询项目子类失败:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('查询项目子类失败:' + res.message)
        })
    },
    initSelectOptions() {
      var vm = this
      getAction(vm.url.codeInfoList, { column: 'code', order: 'Asc',type: '对外科技合作项目成果类型' }).then((res) => {
        if (res.code == 200) {
          var list = res.result
          if (list != null) {
            list.records.map((item) => {
              vm.techMgTypeOption.push({ value: item.code, label: item.name })
            })
          }
        } else {
          this.$message.warning('加载【对外科技合作项目成果类型】选项有误：' + res.message)
        }
      })
      getAction(vm.url.codeInfoList, { column: 'code', order: 'Asc',type: '对外科技合作期望合作方式' }).then((res) => {
        if (res.code == 200) {
          var list = res.result
          if (list != null) {
            list.records.map((item) => {
              vm.cooperationTypeOptions.push({ value: item.code, label: item.name })
            })
          }
        } else {
          this.$message.warning('加载【对外科技合作期望合作方式】选项有误：' + res.message)
        }
      })
    },
    mgTypeChange (value,option) {
      this.form.mgTypeName = option.componentOptions.children[0].text;
    },
    cooperationTypeChange (value,option) {
      this.form.cooperationTypeName = option.componentOptions.children[0].text;
    },
    //如果有id，则加载已填写信息
    initData() {
      if (this.projectBuildId != null && this.projectBuildId != '') {
        var vm = this
        getAction(this.url.queryVOById, { id: this.projectBuildId,changeId: this.changeId })
          .then((res) => {
            if (res.code == 200) {
              var result = res.result
              if (result != null) {
                this.form = result

                vm.hopeDateRange.push(vm.form.hopeStartDate)
                vm.hopeDateRange.push(vm.form.hopeEndDate)

                if (this.form.demandDeptId) {
                  this.demandDeptId = this.form.demandDeptId.split(',')
                  this.loadDemandDeptId(this.form.demandDeptId)
                }

                if (this.form.teamAid) {
                  this.teamAid = this.form.teamAid.split(',')
                  this.loadAUserId(this.form.teamAid)
                }

                if (this.form.landingDeptId) {
                  this.landingDeptId = this.form.landingDeptId.split(',')
                  this.loadLandingDeptId(this.form.landingDeptId)
                }

                this.initSubName()
                this.loadFinish = true
              } else {
                vm.$message.warning('初始化项目信息为空')
              }
            } else {
              this.$message.warning('初始化项目信息失败:' + res.message)
            }
          })
          .catch((res) => {
            this.$message.warning('初始化项目信息失败:' + res.message)
          })
      }else{
        this.loadFinish = true
      }
    },
    initSubName () {
      var vm = this
      getAction(this.url.codeInfoList, { type: '项目子类', isdel: 0,parentid:vm.form.projectClass,code:vm.form.projectType,pageSize:-1})
        .then((res) => {
          if (res.code == 200) {
            var list = res.result
            if (list != null) {
              this.subName = list.records[0].name
            }
          } else {
            this.$message.warning('项目子类:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('项目子类:' + res.message)
        })
    },
    kpiAdd () {
      this.kpi.data.push({
        key: this.kpi.data.length + 1 + new Date().getTime(),
        strId: '',
        companyId: '',
        companyName: '',
      })
    },
    kpiDel () {
      if (this.kpi.selRowIds.length == 0) {
        this.$message.warning('请选择要删除的法人公司记录')
        return
      }
      var vm = this;
      Modal.confirm({
        title: '警告',
        content: '真的要删除吗?',
        okText: '删除',
        okType: 'danger',
        cancelText: '取消',
        onOk () {
          console.log('OK')
          // 在这里调用删除接口
          for (var i = 0; i < vm.kpi.selRowIds.length; i++) {
            for (var j = vm.kpi.data.length - 1; j >= 0; j--) {
              if (vm.kpi.data[j].key == vm.kpi.selRowIds[i]) {
                vm.kpi.data.splice(j, 1)
                break
              }
            }
          }
          vm.kpi.selRowIds = []
          vm.kpi.freshKey++
        },
        onCancel () {
          console.log('Cancel')
        },
      })
    },
    fetchDemandDept(val) {
      if (val) {
        this.demandDeptData = [];
        this.fetching = true;
        getAction(this.url.getDeptList, { name: val }).then(res => {
          if (res.success) {
            this.demandDeptData = res.result;
            this.fetching = false;
          }
        });
      }
    },
    demandDeptChange(value,option) {
      this.$set(this.form,'demandDeptId',value.join(","));
      let arr = []
      option.forEach(item=>arr.push(item.componentOptions.children[0].text?item.componentOptions.children[0].text.trim():''))
      this.$set(this.form,'demandDeptName',arr.join(','));
    },
    loadDemandDeptId(nameList){
      if (nameList) {
        this.demandDeptData = [];
        this.fetching = true;
        getAction(this.url.getDeptList, { nameList: nameList }).then(res => {
          if (res.success) {
            this.demandDeptData = res.result;
            this.fetching = false;
          }
        });
      }
    },
    fetchAUser(val) {
      if (val) {
        this.userAData = [];
        this.fetching = true;
        getAction(this.url.getUserList, { name: val }).then(res => {
          if (res.success) {
            this.userAData = res.result;
            this.fetching = false;
          }
        });
      }
    },
    fetchAChange(value,option) {
      this.$set(this.form,'teamAid',value.join(","));
      let arr = []
      option.forEach(item=>arr.push(item.componentOptions.children[0].text?item.componentOptions.children[0].text.trim():''))
      this.$set(this.form,'teamAname',arr.join(','));
    },
    loadAUserId(nameList){
      if (nameList) {
        this.userAData = [];
        this.fetching = true;
        getAction(this.url.getUserList, { nameList: nameList }).then(res => {
          if (res.success) {
            this.userAData = res.result;
            this.fetching = false;
          }
        });
      }
    },
    fetchLandingDept(val) {
      if (val) {
        this.landingDeptData = [];
        this.fetching = true;
        getAction(this.url.getDeptList, { name: val }).then(res => {
          if (res.success) {
            this.landingDeptData = res.result;
            this.fetching = false;
          }
        });
      }
    },
    landingDeptChange(value,option) {
      this.$set(this.form,'landingDeptId',value.join(","));
      let arr = []
      option.forEach(item=>arr.push(item.componentOptions.children[0].text?item.componentOptions.children[0].text.trim():''))
      this.$set(this.form,'landingDeptName',arr.join(','));
    },
    loadLandingDeptId(nameList){
      if (nameList) {
        this.landingDeptData = [];
        this.fetching = true;
        getAction(this.url.getDeptList, { nameList: nameList }).then(res => {
          if (res.success) {
            this.landingDeptData = res.result;
            this.fetching = false;
          }
        });
      }
    },
    fetchLeaderUser(val) {
      if (val) {
        this.userLeaderData = [];
        this.fetching = true;
        getAction(this.url.getUserList, { name: val }).then(res => {
          if (res.success) {
            this.userLeaderData = res.result;
            this.fetching = false;
          }
        });
      }
    },
    fetchLeaderChange(value,option) {
      this.$set(this.form,'projectLeaderId',value);
      this.$set(this.form,'projectLeaderName',option.componentOptions.children[0].text.trim());
    },
    onDateRangeChange(date, dateString) {
      this.$set(this.form,'hopeStartDate',dateString[0]);
      this.$set(this.form,'hopeEndDate',dateString[1]);
    },
    companySelect (record) {
      this.supplier.visible = true
      this.tableSelectKey = record.key 
    },
    supplierHandleOk(record) {
      if (record != null && record.length > 0) {
        let index = this.kpi.data.findIndex(item=>item.key === this.tableSelectKey)
        if (index != -1) {
          this.kpi.data[index].companyId = record[0].code
          this.kpi.data[index].companyName = record[0].name
        }
      }
      this.supplier.visible = false
    },
    //孵化项目选中
    hatchHandleOk(record) {
      if (record != null && record.length > 0) {
        this.form.hatchProjectId = record[0].id
        this.form.hatchProjectNo = record[0].hatchProjectNo
        this.form.hatchProjectName = record[0].hatchProjectName
 
        this.form.projectLeaderName = record[0].mgTech && record[0].mgTech.projectLeaderName
        this.form.projectLeaderId = record[0].mgTech && record[0].mgTech.projectLeaderId
        this.form.implementPlace = record[0].mgTech && record[0].mgTech.implementPlace
        this.form.solvedProblem = record[0].mgTech && record[0].mgTech.solvedProblem
        this.form.economyTarget = record[0].mgTech && record[0].economyTarget
        this.form.functionAndPerformance = record[0].mgTech && record[0].mgTech.functionAndPerformance
        this.form.cooperationType = record[0].mgTech && record[0].mgTech.cooperationType
        this.form.cooperationTypeName = record[0].mgTech && record[0].mgTech.cooperationTypeName
        this.form.teamAname = record[0].mgTech && record[0].mgTech.teamAname
        this.form.teamAid = record[0].mgTech && record[0].mgTech.teamAid
        this.form.landingDeptName = record[0].mgTech && record[0].mgTech.landingDeptName
        this.form.landingDeptId = record[0].mgTech && record[0].mgTech.landingDeptId
        this.form.demandDeptName = record[0].mgTech && record[0].mgTech.demandDeptName
        this.form.demandDeptId = record[0].mgTech && record[0].mgTech.demandDeptId
        if (this.form.demandDeptId) {
          this.demandDeptId = this.form.demandDeptId.split(',')
          this.loadDemandDeptId(this.form.demandDeptId)
        }

        if (this.form.teamAid) {
          this.teamAid = this.form.teamAid.split(',')
          this.loadAUserId(this.form.teamAid)
        }

        if (this.form.landingDeptId) {
          this.landingDeptId = this.form.landingDeptId.split(',')
          this.loadLandingDeptId(this.form.landingDeptId)
        }
      }
      this.hatch.visible = false
    },
  },
  mounted() {
    if (this.projectBuildId == null || this.projectBuildId == '') {
        this.form.projectType = this.selProjectType
        this.form.projectTypeSubCategory = this.selProjectType
        this.initSubName()
     }
    this.btnShow=this.canDoSave;
    //this.initProjectCategoryOptions()
    this.initSelectOptions()
    this.initData()
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-btn-primary {
  width: 85px;
  height: 30px;
  border-radius: 2px;
  background: #4095e4;
  margin-right: 10px;
}
/deep/ .default {
  width: 85px;
  height: 30px;
  border-radius: 2px;
}
.baseinfo {
  background-color: #fff;
  border: 1px solid #eaeaea;
  padding: 30px;
  .btn {
    display: flex;
    justify-content: center;
  }
}
</style>